﻿@{  
    Layout = "~/_SiteLayout.cshtml";
    Page.Title = "UserVoice API Sample and Documentation";
}

<h3>UserVoice API Methods</h3>
<p>
    This page demonstrates how to use wrapper methods that the UserVoice helper provides on top of select public methods in the UserVoice api.     
</p>

<table class="memberdecls" summary ="UserVoice: method definition and description">
    <caption></caption>
   <thead>
    <tr>
        <th class="memItemLeft" scope="col">&nbsp;</th>
        <th class="memItemRight" scope="col">Method</th>        
	</tr>        
   </thead>
    <tbody>
    <tr>
        <td class="memItemLeft">static void</td>
        <td class="memItemRight"><b>UserVoice.Initialize(string key, string host, [string forum], [string ssoKey], [string apiKey])</b></td>
	</tr>
    <tr>
        <td class="mdescLeft">&nbsp;</td>
        <td class="mdescRight">Initializes the helper with UserVoice settings.</td>        
	</tr>
    
    <tr>
        <td class="memItemLeft">IList&lt;Suggestion&gt;</td>
        <td class="memItemRight"><b>UserVoice.GetSuggestions()</b></td>          
	</tr>
    <tr>
        <td class="mdescLeft">&nbsp;</td>
        <td class="mdescRight">Returns a list of suggestions for the forum id provided to UserVoice.Initialize()</td>        
	</tr>

    <tr>
        <td class="memItemLeft">IList&lt;Suggestion&gt;</td>
        <td class="memItemRight"><b>UserVoice.SearchForSuggestions(query: "<i>searchText</i>")</b></td>        
	</tr>
    <tr>
        <td class="mdescLeft">&nbsp;</td>
        <td class="mdescRight">Returns a list of suggestions whose text contains the search query parameter.</td>        
	</tr>
        
    <tr>
        <td class="memItemLeft">IList&lt;Comment&gt;</td>
        <td class="memItemRight"><b>UserVoice.GetCommentsFromSuggestion(string suggestionId)</b></td>        
	</tr>
    <tr>
        <td class="mdescLeft">&nbsp;</td>
        <td class="mdescRight">Returns the list of comments of the suggestion provided to as a parameter</td>        
	</tr>

    <tr>
        <td class="memItemLeft">IList&lt;Forum&gt;</td>
        <td class="memItemRight"><b>UserVoice.GetForums()</b></td>        
	</tr>
    <tr>
        <td class="mdescLeft">&nbsp;</td>
        <td class="mdescRight">Returns a list of forums for the site provided to UserVoice.Initialize()</td>        
	</tr>

    <tr>
        <td class="memItemLeft">IList&lt;Forum&gt;</td>
        <td class="memItemRight"><b>UserVoice.GetForum()</b></td>        
	</tr>
    <tr>
        <td class="mdescLeft">&nbsp;</td>
        <td class="mdescRight">Returns details about the forum that matches the id provided to UserVoice.Initialize()</td>        
	</tr>
    </tbody>
</table>
<div class="message info">
    <strong>Note:</strong> To use any of these API methods, you need to pass the API key provided to you by UserVoice to the UserVoice.Initialize() method, apiKey parameter.
</div>

<h3>Examples</h3>

<h4>Getting a Suggestions List</h4>
<p>
    In this sample, we'll retreive a list of suggestions, and place the result in a Grid using the WebGrid helper. 
    Find below the code used to retrieve a list of suggestions and populate a WebGrid.
</p>

    @{
        var suggestions = UserVoice.GetSuggestions();
        var grid = new WebGrid(suggestions, canSort: false);
    }
    
    @grid.GetHtml(
        tableStyle : "box",        
        columns: grid.Columns(
            grid.Column(
                header : "Suggestion",
                format : @<text><a href="@item.Url">@item.title</a></text>),
            grid.Column(
                columnName : "vote_count",
                header: "Votes"),
            grid.Column(
                columnName : "supporters_count",
                header : "Supporters"),
            grid.Column(
                header : "Forum",
                format : @<text><span>@item.topic.forum.name</span></text>),
            grid.Column(
                header : "Creator",
                format : @<text><a href="@item.creator.url">@item.creator.name</a></text>)
        )
     )

<pre class="codePre">@@{    
    var suggestions = <b>UserVoice.GetSuggestions();</b>
    var grid = new WebGrid(suggestions, canSort: false);
 }
</pre>

<h4>Searching for Suggestions</h4>
<p>    
    In this sample, we'll search for a list of suggestions that contain the word "blog", and place the result in a Grid using the WebGrid helper. 
    Find below the code used to retrieve a list of suggestions and populate a WebGrid.
</p>
    @{
        var suggestionsSearch = UserVoice.SearchForSuggestions(query: "blog");
        var searchGrid = new WebGrid(suggestionsSearch, canSort: false);
    }
    
    @searchGrid.GetHtml(
        tableStyle : "box",
        columns: grid.Columns(
            grid.Column(
                columnName : "title",
                header : "Suggestion",
                format : @<text><a href="@item.Url">@item.Title</a></text>),
            grid.Column(
                columnName : "vote_count",
                header: "Votes"),
            grid.Column(
                columnName : "supporters_count",
                header : "Supporters"),
            grid.Column(
                header : "Forum",
                format : @<text><span>@item.topic.forum.name</span></text>),
            grid.Column(
                header : "Creator",
                format : @<text><a href="@item.Creator.Url">@item.Creator.Name</a></text>)
        )
     )
    
<pre class="codePre">@@{    
    var suggestionsSearch = <b>UserVoice.SearchForSuggestions(query: "blog");</b>
    var searchGrid = new WebGrid(suggestionsSearch, canSort: false);
 }
</pre>

<h4>Displaying Comments for a Suggestion</h4>
<p>
    In this sample, we'll display comments for one of our suggestions (suggestionId = 1247811), and place the result in a Grid using the WebGrid helper. 
    Find below the code used to retrieve a list of comments and populate a WebGrid.
</p>
    @{
        var comments = UserVoice.GetCommentsForSuggestion(suggestionId: "1247811");
        var commentsGrid = new WebGrid(comments, canSort: false);
    }
    
    @commentsGrid.GetHtml(
        tableStyle : "box",
        
        columns: grid.Columns(
            grid.Column(
                columnName : "text",
                header : "Comment"),
            grid.Column(
                header : "Creator",
                format : @<text><a href="@item.Creator.Url">@item.Creator.Name</a></text>)
        )
     )

<pre class="codePre">@@{    
    var comments = <b>UserVoice.GetCommentsForSuggestion(suggestionId: "1247811");</b>
    var commentsGrid = new WebGrid(comments, canSort: false);
 }
</pre>

<h4>Displaying Forums for an Account</h4>
<p>
    In this sample, we'll display a list of Forums for a UserVoice account, and place the result in a Grid using the WebGrid helper. 
    Find below the code used to retrieve a list of forums and populate a WebGrid.
</p>    
    @{
        var forums = UserVoice.GetForumList();
        WebGrid forumsGrid = new WebGrid(forums, canSort: false);
    }
    
    @forumsGrid.GetHtml(
        tableStyle : "box",        
        columns: grid.Columns(
            grid.Column(
                header: "Forum Id",
                format: @<text><a href="@item.url">@item.id</a></text>),
            grid.Column(
                columnName : "name",
                header : "Forum")
        )
     )
<pre class="codePre">@@{    
    var forums = <b>UserVoice.GetForumList();</b>
    var forumsGrid = new WebGrid(forums, canSort: false);
 }
</pre>

<h4>Displaying a Single Forum</h4>
<p>
In this sample, we'll display information about a single forum, and place the result in a Grid using the WebGrid helper. 
Find below the code used to retrieve a single forum and populate a WebGrid.
</p>
@{
    var forum = new List<dynamic>();
    forum.Add(UserVoice.GetForum());
    var forumGrid = new WebGrid(forum, canSort: false); 
    
        @forumGrid.GetHtml(
        tableStyle: "box",
        columns: grid.Columns(
            grid.Column(
                header: "Forum Id",
                format: @<text><a href="@item.url">@item.id</a></text>),
            grid.Column(
                columnName: "name",
                header: "Forum")
        )
     )
}
    
<pre class="codePre">@@{    
    var forum = <b>UserVoice.GetForum();</b>   
 }
</pre>

<div class="message info">
    For additional API documentation, see the documentation section of your UserVoice Admin site. (Url should be something like the following: <strong>http://<i>yoursite</i>.uservoice.com/admin/docs</strong>)
</div>
